
package com.beans;

import com.entidades.HistoricoPremios;
import java.io.Serializable;  
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.primefaces.event.ItemSelectEvent;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;
  
import org.primefaces.model.chart.PieChartModel;  

@Named("chartB")
public class chartsBean implements Serializable  {  
  
    @PersistenceContext 
    private EntityManager em;
    
    
    //ventas usuarios negocio: VUN
    private CartesianChartModel categoryModel;  
    private List<HistoricoPremios> vListaVUN;
    private HistoricoPremios VUNselected;

    public CartesianChartModel getCategoryModel() {
        return categoryModel;
    }

    public void setCategoryModel(CartesianChartModel categoryModel) {
        this.categoryModel = categoryModel;
    }
    
  
    @PostConstruct
    private void init(){
        createCategoryModel();
    }
    
    private void createCategoryModel() {  
        categoryModel = new CartesianChartModel();  
        ChartSeries uneg = new ChartSeries();  
        uneg.setLabel("Premio");
        
        Query query = em.createNamedQuery("HistoricoPremios.findAll");
        vListaVUN = query.getResultList();
        
        for(int i=0;i<vListaVUN.size();i++){
            uneg.set(vListaVUN.get(i).getApuFecha(), vListaVUN.get(i).getSumPremio());
        }
        categoryModel.addSeries(uneg); 
    }
    
}
